IF EXISTS (SELECT *
           FROM   INFORMATION_SCHEMA.ROUTINES 
           WHERE  routine_name = 'sp_GetTopArticles'
           AND    routine_type = 'Procedure'
           AND    routine_schema = 'dbo' )
BEGIN
   DROP PROCEDURE dbo.sp_GetTopArticles
   IF OBJECT_ID('dbo.sp_GetTopArticles') IS NULL
      PRINT 'DROPPED PROCEDURE dbo.sp_GetTopArticles'
   ELSE
      PRINT 'FAILED DROPPING PROCEDURE dbo.sp_GetTopArticles'
END
GO

CREATE PROCEDURE dbo.sp_GetTopArticles @GetTopArticle     INT
/*****************************************************************/
/* SOW Version 1.0.x                                             */
/*                                                               */
/* Copyright @2005 Spring of Water.      			 */
/*                                                               */
/* 04/21/2005                                                    */
/*                                                               */
/*  The sp performs the following functionality. 		 */
/*  Display most visited articles.                               */
/*  								 */
/*                                                               */
/* ============================================================= */
/* Modification History                                          */
/* ============================================================= */
/* Date:      Developer:       Comment:                          */
/* -----      ----------       --------                          */
/*****************************************************************/
AS

   DECLARE @SelectSQL NVARCHAR(4000)

   SET @SelectSQL = ''

   SET @SelectSQL = 'SELECT Top ' + CAST(@GetTopArticle AS VARCHAR(20)) + '
          [WordID]
         ,[Title]
         ,[CategoryID]
         ,[PartnerID]
         ,[OriginAuthor]
         ,[Description]
         ,[URL]
         ,[Rating]
         ,[EditBy]
         ,[ApproveDate]
         ,[ApproveBy]
	 ,[RecommendDate]
	 ,[RecommendBy]
         ,[Status]
         ,[PublishDate]
         ,ISNULL([IncreaseNumberOfClicks], 0)
   FROM   Word
   ORDER BY [IncreaseNumberOfClicks] DESC'

   EXEC SP_ExecuteSQL @SelectSQL

GO

